package com.stone.design.patterns.observer.javaObserver;


import com.stone.design.patterns.observer.weatherdata.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 4/19/18 22:28
 * @email redsstone@163.com
 */
public class CurrentConditionDisplay implements Observer, DisplayElement{

    private float temp;
    private float humidity;
    private Observable mObservable;

    public CurrentConditionDisplay(Observable observable) {
        this.mObservable = observable;
        observable.addObserver(this);
    }
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) o;
            temp = weatherData.getTemperature();
            humidity = weatherData.getHumidity();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println("Current conditions:" + temp + "F degrees and "
                + humidity + "% humidity");
    }
}
